package cn.maihe.elg.operation.web.order;

import cn.maihe.elg.operation.centers.fuzhou.dto.FZBaseRespDTO;
import cn.maihe.elg.operation.exception.ErrorCode;
import cn.maihe.elg.operation.exception.SystemRuntimeException;
import cn.maihe.elg.operation.service.business.BidCustomerService;
import cn.maihe.elg.operation.service.order.AcceptOrderInfoService;
import cn.maihe.elg.operation.service.order.GuaranteeAttachmentInfoService;
import cn.maihe.elg.operation.service.order.GuaranteeProgressInfoService;
import cn.maihe.elg.operation.service.order.RevokeOrderInfoService;
import cn.maihe.elg.operation.supports.electronicseal.kt.mixca.MixCaSignService;
import cn.maihe.elg.operation.supports.system.ElgResourceService;
import cn.maihe.elg.operation.utils.DownloadExcelTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description 受理出函订单管理
 * @Author Alan
 * @Date 2025/02/20
 */
@Api(value = "订单管理", tags = "订单管理")
@RestController
@RequestMapping("/api")
@Slf4j
public class OrderInfoController {

    @Resource
    private AcceptOrderInfoService acceptOrderInfoService;
    @Resource
    private GuaranteeProgressInfoService guaranteeProgressInfoService;
    @Resource
    private DownloadExcelTool downloadExcelTool;
    @Resource
    private ElgResourceService elgResourceService;
    @Resource
    private BidCustomerService bidCustomerService;
    @Resource
    private RevokeOrderInfoService revokeOrderInfoService;
    @Resource
    private GuaranteeAttachmentInfoService guaranteeAttachmentInfoService;
    @Resource
    private MixCaSignService mixCaSignService;

    @ApiOperation(value = "保函作废", notes = "保函作废")
    @RequestMapping(value = "/acceptOrder/invalid/{id}", method = RequestMethod.POST)
    public FZBaseRespDTO invalidGuarantee(@PathVariable String id, @RequestBody Map<String, String> map) {

        String backReasonDetail = map.get("backReasonDetail");

        if (null == backReasonDetail || backReasonDetail.isEmpty()) {
            throw new SystemRuntimeException(ErrorCode.ERROR, "函撤销原因不能为空");
        }

        return acceptOrderInfoService.invalidGuarantee(id, backReasonDetail);
    }

    @ApiOperation(value = "理赔成功", notes = "理赔成功")
    @RequestMapping(value = "/acceptOrder/claim/{id}", method = RequestMethod.POST)
    public FZBaseRespDTO claimSettlement(@PathVariable String id, @RequestBody Map<String, String> map) {

        String claimReason = map.get("claimReason");

        if (null == claimReason || claimReason.isEmpty()) {
            throw new SystemRuntimeException(ErrorCode.ERROR, "函撤销原因不能为空");
        }

        return acceptOrderInfoService.claimSettlement(id, claimReason);
    }
}
